const app = getApp();
Page({
  data: {
    order: {},
    refund:['仅退款','退货退款'],
    reason: ['不想要了','多买/错买','商品和描述不符'],
    apply_desc:'',
  },
  onLoad: function (options) {
    let refund = ['仅退款','退货退款'];
    if(options.type == "1"){
      refund = ['仅退款'];
    }
    this.setData({
      order_id: options.id,
      refund: refund
    })
  },
  onShow: function () {

  },
  getFormid(e){
    app.getFormid(e);
  },
  refundChange(e) {
    this.setData({
      refundValue: this.data.refund[e.detail.value]
    })
  },
  reasonChange(e) {
    this.setData({
      reasonValue: this.data.reason[e.detail.value]
    })
  },
  getInput(e){
    let that = this;
    that.setData({
      apply_desc: e.detail.value,
    })
  },
  sure(e){
    let that = this;
    let order_id = that.data.order_id;
    let type = that.data.refundValue || '';
    let apply_reason = that.data.reasonValue || '';
    let apply_desc = that.data.apply_desc;
    if (!type){
      wx.showToast({
        title: '请选择退款类型',
        icon: 'none',
      })
      return false;
    }
    if (!apply_reason) {
      wx.showToast({
        title: '请选择退款原因',
        icon: 'none',
      })
      return false;
    }
    app.request('order/applyService', {
      order_id, type, apply_reason, apply_desc
    },'GET',false,function(res){
      wx.showToast({
        title: '提交成功',
        mask: true,
      })
      setTimeout(()=>{
        wx.navigateBack({
          delta: 2,
        })
      },1500)
    })
  },
  onShareAppMessage(){
    return{
      path: '/pages/index/index'
    }
  }
  
})